//
//  TabMeViewController.m
//  TableBarControllerDemo
//
//  Created by 边果互动 on 2021/3/15.
//

#import "TabMeViewController.h"
#import "MeTitleBgViewCell.h"
#import "MeViewCell.h"

#define cell_id_meTitleBg @"MeTitleBgViewCell"
#define cell_id_meView @"MeViewCell"

@interface TabMeViewController ()

@end

@implementation TabMeViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    CGRect frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight - Status_NavBar);
    [self createTableViewWithFrame:frame];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, NavBarHeight, 0);
    self.tableView.backgroundColor = COLOR_BG;
    [self.view addSubview:self.tableView];
    
    [self.tableView registerNib:[UINib nibWithNibName:cell_id_meTitleBg bundle:nil] forCellReuseIdentifier:cell_id_meTitleBg];
    [self.tableView registerNib:[UINib nibWithNibName:cell_id_meView bundle:nil] forCellReuseIdentifier:cell_id_meView];
}

#pragma mark - UITableViewDataSouource代理
//返回有几组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

//返回每组有几条数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (0 == section) {
        return 1;
    }
    return 5;
}

//返回每条数据的内容，cell
//indexPath.section表示组的下标
//indexPath.row表示该组下的item的下标
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (0 == indexPath.section) {
        MeTitleBgViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id_meTitleBg forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [self addShadow:cell.shadowView];
        cell.onClick = ^(id  _Nonnull view) {
            if (view == cell.releaseBtn) {
                MLog(@"点击了发布按钮");
            } else if (view == cell.galleryBtn) {
                MLog(@"点击了图库按钮");
            } else if (view == cell.walletBtn) {
                MLog(@"点击了钱包按钮");
            } else if (view == cell.collectBtn) {
                MLog(@"点击了收藏按钮");
            }
        };
        return cell;
    } else {
        MeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id_meView forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        switch (indexPath.row) {
            case 0:
                cell.iconIv.image = [UIImage imageNamed:@"person_法律条款"];
                cell.contentTv.text = @"法律条款";
                break;
            case 1:
                cell.iconIv.image = [UIImage imageNamed:@"person_关于我们"];
                cell.contentTv.text = @"关于我们";
                break;
            case 2:
                cell.iconIv.image = [UIImage imageNamed:@"person_邀请好友"];
                cell.contentTv.text = @"邀请好友";
                break;
            case 3:
                cell.iconIv.image = [UIImage imageNamed:@"person_使用帮助"];
                cell.contentTv.text = @"使用帮助";
                break;
            case 4:
                cell.iconIv.image = [UIImage imageNamed:@"person_系统设置"];
                cell.contentTv.text = @"系统设置";
                break;
            default:
                break;
        }
        return cell;
    }
    return nil;
}

//返回每一行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (0 == indexPath.section) {
        return 270;
    }
    return 55;
}

//点击事件在这里处理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (1 == indexPath.section) {
        switch (indexPath.row) {
            case 0:
                NSLog(@"法律条款");
                break;
            case 1:
                NSLog(@"关于我们");
                break;
            case 2:
                NSLog(@"邀请好友");
                break;
            case 3:
                NSLog(@"使用帮助");
                break;
            case 4:
                NSLog(@"系统设置");
                break;
            default:
                break;
        }
    }
}

//组头将要显示的时候调用，可以在这里给组头设置颜色
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    
}

//组尾将要显示的时候调用，可以在这里给组尾设置颜色
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
